<template>
  <div class="container">
    <div class="logo">
      <img src="@/assets/brand-logo.png" alt="" />
    </div>
    <el-row class="area">
      <el-col :span="8" class="left-area">
        <div class="edit">
          <div>
            <div class="title">登录到</div>
            <div class="title">天罡阵安保系统</div>
          </div>
          <div>
            <span class="plain-text">没有账号吗？</span>
            <el-button type="primary" link>注册新账号</el-button>
          </div>
          <el-input size="large" placeholder="请输入内容" :prefix-icon="User" v-model="username"></el-input>
          <el-input type="password" size="large" placeholder="请输入密码" :prefix-icon="Lock" v-model="password"></el-input>
          <div class="row-between">
            <el-checkbox label="记住账号"></el-checkbox>
            <el-button type="primary" link>忘记密码？</el-button>
          </div>
          <div class="gl-main-button" @click="handleLogin">登录</div>
          <div>
            <el-button type="primary" link>使用微信扫码登录</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button type="primary" link>使用短信登录</el-button>
          </div>
          <div class="copyright plain-text">Copyright @ 2022-2024 Fornaxignis. All Rights Reserved</div>
        </div>
      </el-col>
      <el-col :span="16"></el-col>
    </el-row>
  </div>
</template>

<script setup>
import { handleApiError, API } from '@/api';
import { User, Lock } from '@element-plus/icons-vue';
import { ref } from 'vue'
import { useRouter } from 'vue-router';
const router = useRouter()
const username = ref('admin')
const password = ref('123456')

const handleLogin = () => {
  if (username.value && password.value) {
    handleApiError(async () => {
      await API.user.login({
        username: username.value,
        password: password.value
      })
      ElMessage({
        type: "success",
        message: "登录成功",
        duration: 1000
      });
      router.push({
        name: "default"
      })
    })
  } else {
    ElMessage({
      message: "提示: 请先输入用户名和密码",
      type: "error",
      duration: 2000,
    });
  }
}

</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  background-color: var(--background-color);
  background-image: url('@/assets/login-bkg.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding: 0 50px;

  .logo {
    position: absolute;
    z-index: 2;
    top: 10px;
    left: 10px;
    width: 250px;
    height: 70px;
    border-radius: 5px;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;

    img {
      width: 90%;
    }
  }

  .area {
    height: 100%;
  }

  .left-area {
    display: flex;
    justify-content: center;
    align-items: center;

    .edit {
      height: 60%;
      width: 100%;
      min-width: 280px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;

      .title {
        font-size: 2em;
        font-weight: bold;
      }

      .plain-text {
        color: var(--second-text-color);
      }

      .row-between {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .gl-main-button {
        width: 100%;
      }

      .copyright {
        position: absolute;
        bottom: 50px;
      }
    }
  }
}
</style>
